package com.bawei.park2212.patrols

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_common.view.entity.PatrolTaskBeanItem
import com.example.module_service.R
import com.example.module_service.databinding.ItemTaskBinding

class TaskAdapter:BaseQuickAdapter<PatrolTaskBeanItem,BaseViewHolder>(R.layout.item_task){
    lateinit var binding: ItemTaskBinding

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemTaskBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: PatrolTaskBeanItem) {
        binding = DataBindingUtil.getBinding<ItemTaskBinding>(helper.itemView)!!
        binding.bean = item

        when(item.patrolStatus){
            "0"->{
                binding.taskType.apply {
                    setText("未巡检")
                    setBackgroundResource(com.example.lib_common.R.drawable.shape_solid_white)
                    setTextColor(context.getColor(R.color.blue))
                }
            }
            "1"->{
                binding.taskType.apply {
                    setText("巡检中")
                    setBackgroundResource(com.example.lib_common.R.drawable.shape_weihu)
                    setTextColor(context.getColor(R.color.orange))
                }
            }
            "2"->{
                binding.taskType.apply {
                    setText("已完成")
                    setBackgroundResource(com.example.lib_common.R.drawable.shape_status)
                    setTextColor(context.getColor(R.color.green))
                }
            }
            else-> {
                binding.taskType.apply {
                    setText("已作废")
                    setBackgroundResource(com.example.lib_common.R.drawable.shape_weihu)
                    setTextColor(context.getColor(R.color.darkgray))
                }
            }
        }
    }
}